<?php

/*
template name: Registrazione Professionisti
 */
get_header();
?>
<div id="contenuti">
    <div id="sottomenu">
        <ul>
            <li class="ultimo"><strong>Registrazione area Professionisti</strong></li>
        </ul>
    </div>
    <span>Per accedere a questa area devi effettuare il <a href="<?php bloginfo('url') ?>/login">Login</a> oppure registrarti.</span>
    <form method="" id="adduserForm" name="adduserForm" action="">
            <div class="agree">
                <label for="agree"><?php _e('Accetto'); ?>
                    <?php $agree = get_the_author_meta('agree', $current_user->ID);
                    ?>
                    <input value="Yes" name="agree" type="radio" />
                </label>
                <label for="agree"><?php _e('Non accetto'); ?>
                    <input value="No" name="agree"  type="radio" />
                </label>

                <div class="errore">
                    <span class="obb" id="req_discl">Per procedere con la registrazione devi accettare i termini</span>
                </div>
            </div>
            <div id="username">
                <label for="user_name"><?php _e('Username *'); ?></label>
                <input name="user_name" type="text" id="user_name" value="<?php if ($error) echo wp_specialchars($_POST['user_name'], 1); ?>" />
                <div class="errore"><span class="obb" id="req_username">La username &egrave; obbligatoria</span></div>
                <div id="nome">
                    <label for="first_name"><?php _e('Nome'); ?></label>
                    <input name="first_name" type="text" id="first_name" value="<?php if ($error) echo wp_specialchars($_POST['first_name'], 1); ?>" />
                </div>
                <div id="cognome">
                    <label for="last_name"><?php _e('Cognome'); ?></label>
                    <input name="last_name" type="text" id="last_name" value="<?php if ($error) echo wp_specialchars($_POST['last_name'], 1); ?>" />
                </div>
                <div id="titolo">
                    <div class="errore">
                        <span class="obb" id="req_titolo">Devi inserire il tuo titolo</span>
                    </div>
                    <div id="titolo-inner">
                        <select name="titolo">
                            <option value="">Scegli titolo</option>
                            <option value="Dott.">Dott./ssa</option>
                            <option value="Prof.">Professionista</option>
                        </select>
                    </div>
                </div>
                <div id="specializzazione">
                    <div class="errore">
                        <span class="obb" id="req_specializzazione">Devi inserire la specializzazione</span>
                    </div>
                    <div id="specializzazione-inner">
                        <select name="specializzazione">
                            <option value="">Specializzazione</option>
                            <option name="ginecologo">
                                Ginecologo
                            </option>
                            <option name="andrologo">
                                Andrologo
                            </option>
                        </select>
                    </div>
                </div>
                <div id="e-mail">
                    <div class="errore">
                        <span class="obb" id="req_mail">L'indirizzo e-mai &egrave; obbligatorio</span>
                    </div>
                    <label for="email"><?php _e('E-mail *'); ?></label>
                    <input name="email" type="text" id="email" value="<?php if ($error) echo wp_specialchars($_POST['email'], 1); ?>" />
                </div>
                <div id="invia">
                    <?php echo $referer; ?>
                    <input name="adduser" type="button" id="addusersub" class="submit button" value="<?php
                if (current_user_can('create_users')) {
                    _e('Registrati');
                } else {
                    _e('Register');
                }
                    ?>" />
                           <?php wp_nonce_field('add-user') ?>
                    <input name="action" type="hidden" id="action" value="adduser" />
                </div>
        </form>
    <script>
         var blurl= '<?php echo get_option('siteurl'); ?>';
         $(document).ready(function(){
          $('form .obb').hide();
        $('#addusersub').click(function(evt){
            $('form .obb').hide();
            evt.preventDefault();
            $.ajax({
                type: 'POST',
                data: $('#adduserForm').serialize(),
                url: blurl+"/wp-admin/admin-ajax.php?action=registerProf",
                success: function(data){
                    //alert(data.ok);
                    if (data.ok == '3') {
                        Dialog(data.message); 
                        $('form input[type=text],textarea').val('');
                    }else if(data.ok==0){
                        Dialog(data.message);
                        $.each(data.campi, function(i,e){
                            // $('form .obb').show();
                            var c= '#req_'+e;
                            //alert(c);
                            $(c).show();
                        });
                    }
                },
                error: function(data){
                    alert(data);
                }
                
            }); 
        });
        
        function Dialog(str){
            str = '<div class="alert"><div class="chiudi"><a href="#"></a></div><div class="boxGradiente gradient">'+str+'</div></div>';
            
            $.blockUI({
                message: str,
                onBlock: function(){
                    $(".chiudi").click(function() {
                        $.unblockUI();
                    });
                }
            });
        }
         });
    </script>
    
</div>



<?php 
get_footer();

?>
